/* eslint-disable import/no-extraneous-dependencies */
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import vitePluginImp from 'vite-plugin-imp';
import { viteMockServe } from 'vite-plugin-mock';

// https://vitejs.dev/config/
export default defineConfig(({ command }) => ({
  server: {
    host: true,
    port: 8888,
  },
  resolve: {
    alias: [
      { find: /^~/, replacement: '' },
      { find: /^@src/, replacement: path.resolve(__dirname, 'src') },
      { find: /^@api/, replacement: path.resolve(__dirname, 'src/api') },
      { find: /^@assets/, replacement: path.resolve(__dirname, 'src/assets') },
      { find: /^@components/, replacement: path.resolve(__dirname, 'src/components') },
      { find: /^@common/, replacement: path.resolve(__dirname, 'src/common') },
    ],
  },
  css: {
    modules: {
      localsConvention: 'camelCaseOnly',
    },
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
      },
    },
  },
  plugins: [
    react(),
    vitePluginImp({
      libList: [
        {
          libName: 'antd',
          style(name) {
            // use less
            return `antd/es/${name}/style/index.js`;
          },
        },
      ],
    }),
    viteMockServe({
      // default
      mockPath: 'mock',
      localEnabled: command === 'serve',
    }),
  ],
}));
